<?php
/**
 * 取消点赞和关注接口
 */
require_once "login_filter.php";
//require_once dirname(__DIR__) . "/common.php";
//$my_uuid=3;
use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\model\HomePage;
$my_uuid=$Auth['uuid'];
//1.判断接收的参数
if($_REQUEST['type']==0){
    if(empty($_REQUEST['video_uuid']) || empty($_REQUEST['uuid'])){
        Response::output(-1,"参数错误fa");
    }
    $type="fabulous";
}else if($_REQUEST['type']==1){
    if(empty($_REQUEST['uuid'])){
        Response::output(-1,"参数错误fo");
    }
    $type="follow";
}else{
    Response::output(-1,"参数错误1");
}
//凭接入队列参数
$where['my_uuid']=$my_uuid;
if(!empty($_REQUEST['video_uuid'])){
    $where['video_uuid']=$_REQUEST['video_uuid'];
}
if(!empty($_REQUEST['uuid'])){
    $where['other_uuid']=$_REQUEST['uuid'];
}
if(!empty($_REQUEST['select_id'])){
    $where['other_id']=$_REQUEST['select_id'];
}
//实例化redis
$redis = SysResource::getRedis();
$suffix=rand(1,5);
//2.设置可以值
$uid=sprintf("%d",crc32($where['my_uuid']));//这是我的uuid
$oid=sprintf("%d",crc32($where['other_uuid']));//他人的uuid
//正式地址
$key = REDIS_PREFIX."{$type}_del_".$suffix;
$key1=REDIS_PREFIX."{$type}_".$uid;
$key11=REDIS_PREFIX."is_{$type}_".$oid;//这是他人的粉丝列表
$user_material_love_key=REDIS_PREFIX."user_material_love_del_".$suffix;//用户视频被点赞
//测试地址
//$key = REDIS_PREFIX."test_{$type}_del_".$suffix;
//$key1=REDIS_PREFIX."test_{$type}_".$uid;
//$key11=REDIS_PREFIX."test_is_{$type}_".$oid;//这是他人的粉丝列表
//$user_material_love_key=REDIS_PREFIX."test_user_material_love_del_".$suffix;//用户视频被点赞

//if($_REQUEST['type']==0){
//    $key1=REDIS_PREFIX."{$type}_".$uid;
//}else if($_REQUEST['type']==1){
//    $key1=REDIS_PREFIX."{$type}_".$uid;//这是我的关注列表
//    $key11=REDIS_PREFIX."is_{$type}_".$oid;//这是他人的粉丝列表
//}else{
//    Response::output(-1,"参数错误2");
//}
//3.先去删除redis里的数据
if($_REQUEST['type']==0){
    //redis里点赞不为空
    $da1=$redis->HKEYS($key1);
    //redis里点赞为空
    if(!empty($da1)){
        if(in_array($_REQUEST['video_uuid'],$da1)){
            $res1=$redis->hDel($key1,$_REQUEST['video_uuid']);
        }
    }
    //2.1再把用户点赞的视频同步到用户上传表的字段，先入队列
    $user_material_love_key_data['video_uuid']=$where['video_uuid'];
    $user_material_love_key_data['id']=$where['other_id'];
    $redis->lPush($user_material_love_key,json_encode($user_material_love_key_data));

}else if($_REQUEST['type']==1){
    //redis里关注不为空
    $da2=$redis->HKEYS($key1);
    if(!empty($da2)){
        if(in_array($_REQUEST['uuid'],$da2)){
            $res2=$redis->hDel($key1,$_REQUEST['uuid']);
        }
    }
    //粉丝redis不为空
    $da3=$redis->hKeys($key11);
    if(!empty($da3)){
        if(in_array($_REQUEST['uuid'],$da3)){
            $res3=$redis->hDel($key11,$_REQUEST['uuid']);
        }
    }
}
//4.再把数据入队列，删除数据库的数据
$redis->lPush($key,json_encode($where));
Response::output(0,"删除成功",$type."_".$suffix);
